$(document).ready(
		function() {
			
			var rootPath = getRootPath();

			$.ajax({
				headers: {'Cookie' : document.cookie },
				method : 'get',
				url : rootPath+'/customer/api/v1/fans',
				error:function(XMLHttpRequest, ajaxOptions, thrownError){
					//alert("数据刷新失败");
				},
				success : function(resultData){
					if(resultData.length==0){
						//不是会员
						alert("请先注册成为会员！");
						window.location = rootPath + "/views/homepage/signUp.html";
					}else{
						//是会员
					}
				}
			});
//			alert("开始");
			$.ajax({
				headers: {'Cookie' : document.cookie },
				method : 'get',
				url : rootPath+'/customer/api/v1/potentialInfo',
				error:function(XMLHttpRequest, ajaxOptions, thrownError){
//					alert("错误");
					//alert("数据刷新失败");
				},
				success : function(resultData){
					$.each(resultData,function(memberInfoIndex,memberInfoObj){
							$("#potentialUserId").val(memberInfoObj.potentialUserId);
							$("#identifyingCode").val(memberInfoObj.identifyingCode);
							$("#identifyingCodeDate").val(memberInfoObj.identifyingCodeDate);
//							alert("成功");
						});
				}
			});

})
//修改按钮
function sure(){
	var carOwnerDto = {
			"phone" : $("#phone").val(),
			"identifyingCode" : $("#yan").val(),
			"potentialUserId" : $("#potentialUserId").val(),
		};
		$.ajax({
			headers: {'Cookie' : document.cookie },
			type : "POST",
			url : rootPath + "/customer/api/v1/updatePhone",
			dataType : "json",
			contentType : "application/json",
			data : JSON.stringify(carOwnerDto),
			success : function(resultDate) {
	        	var data=eval(resultDate);
	        	alert(data.resultMsg);
	        	if(data.resultMsg=='修改成功!'){
					window.location = rootPath + "/views/homepage/personData.html";
	        	}else{
	        		location.reload();
	        	}
			},
			error : function(data) {
				alert("你的修改失败了");
				//alert("修改失败！");
			}
		});
}
var wait=60;
function time(o) {
  if (wait == 0) {
   o.removeAttribute("disabled");   
   o.value="获取验证码";
   wait = 60;
  } else { 
 
   o.setAttribute("disabled", true);
   o.value="重新发送(" + wait + ")";
   wait--;
   setTimeout(function() {
    time(o)
   },
   1000)
  }
 }
//点击获取验证码
function GetRandom(o){
	var phone = $("#phone").val();
	if(!$("#phone").val().match(/^1[34578]\d{9}$/)){
		alert("请输入正确的手机号码！");
		$("#phone").focus();
	}else{
	//生成验证码
	var Num=""; 
	for(var i=0;i<6;i++) 
	{ 
		Num+=Math.floor(Math.random()*10); 
	}
	$("#identifyingCode").val(Num);
	var identifyingCodeDto = {"identifyingCode":$("#identifyingCode").val(),
							"potentialUserId":$("#potentialUserId").val(),
							"phone":$("#phone").val()
	}
	$.ajax({
		headers: {'Cookie' : document.cookie },
		type : "POST",
		url : rootPath + "/customer/api/v1/updateCode",
		dataType : "json",
		contentType : "application/json",
		data : JSON.stringify(identifyingCodeDto),
		success : function(data) {
			//alert("更新成功！");
			//location.reload();
		},
		error : function(data) {
			//alert("更新失败！");
		}
	});
	time(o);
  }
}

//jquery验证手机号码
function checkSubmitMobil() {
if ($("#phone").val() == "") {
alert("手机号码不能为空！");
//$("#moileMsg").html("<font color='red'>手机号码不能为空！</font>");
$("#phone").focus();
return false;
}
if (!$("#phone").val().match(/^1[34578]\d{9}$/)) {
alert("手机号码格式不正确！");
//$("#moileMsg").html("<font color='red'>手机号码格式不正确！请重新输入！</font>");
$("#phone").focus();
return false;
}
if ($("#yan").val() == "") {
	alert("验证码不能为空！");
	//$("#moileMsg").html("<font color='red'>手机号码不能为空！</font>");
	$("#phone").focus();
	return false;
	}
sure();
return true;
} 